// UpdateCallbackGUI.h

#ifndef __UPDATE_CALLBACK_GUI_H
#define __UPDATE_CALLBACK_GUI_H

#include "Common/Archive/Update.h"
#include "Common/Archive/ArchiveOpenCallback.h"
#include "../FileManager/ProgressDialog2.h"

class ATL_NO_VTABLE CUpdateCallbackGUI:
	public CComObjectRootEx<CComSingleThreadModel>,
  public IOpenCallbackUI,
  public Common::Archive::IUpdateCallbackUI2
{
public:

	BEGIN_COM_MAP(CUpdateCallbackGUI)
		COM_INTERFACE_ENTRY(IOpenCallbackUI)
		//COM_INTERFACE_ENTRY(Common::Archive::IUpdateCallbackUI2) no GUID
	END_COM_MAP()

	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		Init();
		return S_OK;
	}

	void FinalRelease()
	{
	}

  bool PasswordIsDefined;
  CString Password;
  bool AskPassword;
  bool PasswordWasAsked;
  UINT64 NumFiles;

  CUpdateCallbackGUI():
      PasswordIsDefined(false),
      PasswordWasAsked(false),
      AskPassword(false)
      {}
  
  ~CUpdateCallbackGUI();
  void Init();

    // INTERFACE IUpdateCallbackUI 
  STDMETHOD(SetTotal)(UINT64 size) ;
  STDMETHOD(SetCompleted)(const UINT64 *completeValue) ;
  STDMETHOD(SetRatioInfo)(const UINT64 *inSize, const UINT64 *outSize) ;
  STDMETHOD(CheckBreak)() ;
  STDMETHOD(Finilize)() ;
  STDMETHOD(SetNumFiles)(UINT64 numFiles) ;
  STDMETHOD(GetStream)(const wchar_t *name, bool isAnti) ;
  STDMETHOD(OpenFileError)(const wchar_t *name, DWORD systemError) ;
  STDMETHOD(SetOperationResult)(INT32 operationResult) ;
  STDMETHOD(CryptoGetTextPassword2)(INT32 *passwordIsDefined, BSTR *password) ;
  STDMETHOD(CryptoGetTextPassword)(BSTR *password) ;
  /* STDMETHOD(ShowDeleteFile(const wchar_t *name); */ 
  /* STDMETHOD(CloseProgress() { return S_OK; }; */

  //INTERFACE IUpdateCallbackUI2
  STDMETHOD(OpenResult)(const wchar_t *name, HRESULT result) ;
  STDMETHOD(StartScanning)();
  STDMETHOD(ScanProgress)(UINT64 numFolders, UINT64 numFiles, const wchar_t *path) ;
  STDMETHOD(CanNotFindError)(const wchar_t *name, DWORD systemError) ;
  STDMETHOD(FinishScanning)() ;
  STDMETHOD(StartArchive)(const wchar_t *name, bool updating) ;
  STDMETHOD(FinishArchive)() ;
  //INTERFACE IOpenCallbackUI
	STDMETHOD(Open_CheckBreak)() ;
	STDMETHOD(Open_SetTotal)(const UINT64 *files, const UINT64 *bytes) ;
	STDMETHOD(Open_SetCompleted)(const UINT64 *files, const UINT64 *bytes) ;
  
	//INTERFACE IOpenCallbackUI_Crypto
	STDMETHOD(Open_CryptoGetTextPassword)(BSTR *password) ;
	STDMETHOD(Open_GetPasswordIfAny)(CString &password) ;
	virtual bool Open_WasPasswordAsked() ;
	virtual void Open_ClearPasswordWasAskedFlag() ;

  CStringVector FailedFiles;

  CProgressDialog2 *ProgressDialog;

  void AddErrorMessage(LPCTSTR message);
  void AddErrorMessage(const TCHAR *name, DWORD systemError);
};

#endif
